package com.sigmazero13.gameutils.utils;

import java.io.File;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.sigmazero13.gameutils.R;

public class FileArrayAdapter extends ArrayAdapter<File> {

	private Context context;
	private int resourceId;
	private List<File> files;
	
	public FileArrayAdapter(Context context, int textViewResourceId, List<File> files) {
		super(context, textViewResourceId, files);
		this.context = context;
		resourceId = textViewResourceId;
		this.files = files;
	}
	
	public File getFile(int i) {
		return files.get(i);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(resourceId, null);
		}
		final File f = getFile(position);
		if (f != null) {
			TextView fileView = (TextView)v.findViewById(R.id.list_item_text);
			fileView.setText(f.getName());
		}
		
		return v;
	}
}
